// 引入 gulp
var gulp = require('gulp');

// 引入组件
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var less = require('gulp-less');
var cssmin = require('gulp-minify-css');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var combo = require('gulp-seajs-combo');
var del = require('del');
// 检查脚本
gulp.task('lint', function() {
   gulp.src('./js/*.js')
       .pipe(jshint())
       .pipe(jshint.reporter('default'));
});

//先删除文件
gulp.task('cleanFile', function (cb) {
   del(['./weixinWeb/release/css/*','./weixinWeb/release/js/business/main.min.js','./weixinWeb/release/js/business/openclass.min.js'],cb)
});

 //只压缩css文件
// gulp.task('minicss', function() {
//    return gulp
//       .src(['./weixinWeb/src/css/ini_t.css','./weixinWeb/src/css/chat.css','./weixinWeb/src/css/main.css'])
//        .pipe(concat('main.css'))
//        .pipe(cssmin())
//        .pipe(rename({suffix:'.min'}))
//        .pipe(gulp.dest('./weixinWeb/release/css'));
// });
//把LESS文件压缩并转成CSS文件
gulp.task('mainless', function() {
   return gulp
       .src(['./weixinWeb/src/css/main.less'])
      // .pipe(concat('main.less'))
       .pipe(less())
       .pipe(cssmin())
       .pipe(rename({suffix:'.min'}))
       .pipe(gulp.dest('./weixinWeb/release/css'));
});
gulp.task('openless', function() {
    return gulp
        .src(['./weixinWeb/src/css/openclass.less'])
       // .pipe(concat('openclass.less'))
        .pipe(less())
        .pipe(cssmin())
        .pipe(rename({suffix:'.min'}))
        .pipe(gulp.dest('./weixinWeb/release/css'));
});
// 合并，压缩文件
//直播页JS
// gulp.task('mainscripts', function() {
//     return gulp
//         .src(['./weixinWeb/src/js/plug/main.js'])
//         //.pipe(combo())
//         //.pipe(concat('openclass.js'))
//         //.pipe(gulp.dest('./weixinWeb/release/js/business'))
//         .pipe(rename('main.min.js'))
//         .pipe(uglify())
//         .pipe(gulp.dest('./weixinWeb/release/js/business'));
// });

gulp.task('mainscripts', function() {
    return gulp
        .src(['./weixinWeb/src/js/plug/sea.js','./weixinWeb/src/js/plug/sea.config.js','./weixinWeb/src/js/plug/zepto.min.js','./weixinWeb/src/js/business/socket.io.js','./weixinWeb/src/js/business/main.js'])
        .pipe(concat('main.js'))
        .pipe(rename('main.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('./weixinWeb/release/js/business'));
});

//直播前页JS
gulp.task('opencla_wxs', function() {
   return gulp
       .src(['./weixinWeb/src/js/plug/sea.js','./weixinWeb/src/js/plug/sea.config.js','./weixinWeb/src/js/plug/zepto.min.js','./weixinWeb/src/js/plug/iscroll.js','./weixinWeb/src/js/business/openclass_wxs.js'])
       .pipe(concat('openclass_wxs.js'))
       .pipe(rename('openclass_wxs.min.js'))
       .pipe(uglify())
       .pipe(gulp.dest('./weixinWeb/release/js/business'));
});
//直播前页-金山-订阅号
gulp.task('openclass', function() {
    return gulp
        .src(['./weixinWeb/src/js/plug/zepto.min.js','./weixinWeb/src/js/business/openclass.js'])
        .pipe(concat('openclass.js'))
        .pipe(rename('openclass.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('./weixinWeb/release/js/business'));
});

//gulp.task('clientscripts', function() {
//    gulp.src(['./src/js/business/chat.js','./src/js/business/handShake.js','./src/js/business/comm_server.js','./src/js/business/paintWeb.js'
//        ,'./src/js/business/touchSwiper.js','./src/js/business/userSlide.js','./src/js/business/zTouch.js'])
//        .pipe(concat('client.js'))
//        .pipe(gulp.dest('./release/js/business'))
//        .pipe(rename('client.min.js'))
//        .pipe(uglify())
//        .pipe(gulp.dest('./release/js/business'));
//});


// gulp.task('mainscripts', function() {
//    gulp.src(['./src/js/business/model.js','./src/js/business/ready.js'])
//        .pipe(concat('main.js'))
//        .pipe(gulp.dest('./src/js/business'))
//        .pipe(rename('main.min.js'))
//        .pipe(uglify())
//        .pipe(gulp.dest('./src/js/business'));
// });

//gulp.task('socketscripts', function() {
//    gulp.src(['./src/js/business/socket.io.js'])
//        .pipe(concat('socket.io.js'))
//        .pipe(gulp.dest('./src/js/business'))
//        .pipe(rename('socket.io.min.js'))
//        .pipe(uglify())
//        .pipe(gulp.dest('./src/js/business'));
//});
//gulp.task('zeptoscripts', function() {
//    gulp.src(['./src/js/plug/zepto.js'])
//        .pipe(concat('zepto.js'))
//        .pipe(gulp.dest('./src/js/plug'))
//        .pipe(rename('zepto.min.js'))
//        .pipe(uglify())
//        .pipe(gulp.dest('./src/js/plug'));
//});

// 默认任务

gulp.task('default',['cleanFile','mainscripts','mainless','openless','opencla_wxs','openclass']);

//gulp.task('default', function(){
//    //gulp.run('lint', 'clientscripts','readyscripts','commonscripts','socketscripts','zeptoscripts');
//        gulp.run('mainscripts');
//    // 监听文件变化
//    gulp.watch(['./src/js/business/*.js','./src/js/plug/*.js'], function(){
//        gulp.run('mainscripts');
//    });
//});